/*    file: SdlDoubleClick.cpp
 *    desc:
 * 
 * created: 2014-04-19 09:26:19
 *  author: zhengchuanjiang
 * company: 
 */

#include "SdlDoubleClick.h"

namespace sdl
{

DoubleClick::DoubleClick():
    m_ticks(),
    m_elapse(500)
{

}

DoubleClick::~DoubleClick()
{

}

bool DoubleClick::isDoubleClick(SDL_Event& sdlEvent)
{
    bool isDouble = false;
    if (sdlEvent.type == SDL_MOUSEBUTTONDOWN)
    {
        Uint32 ticks = SDL_GetTicks();
        isDouble = (ticks - m_ticks) < m_elapse;

        m_ticks = ticks;
    }
    else if (sdlEvent.type == SDL_MOUSEBUTTONUP)
    {
        // pass
    }
    else
    {
        reset();
    }

    return isDouble;
}

void DoubleClick::setClickElapse(Uint32 ms)
{
    if (ms <= 1)
    {
        return;
    }

    m_elapse = ms;
}

void DoubleClick::reset()
{
    m_ticks = 0;
}



}


